package com.minhua.jijiehao2.mainframe.mine.updatenicknameactivity.impl

import android.content.Intent
import android.os.Handler
import android.view.View
import com.minhua.jijiehao2.R
import com.minhua.jijiehao2.base.BaseActivity
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.mainframe.main.impl.MainActivity
import com.minhua.jijiehao2.mainframe.mine.updatenicknameactivity.imp.IUpdateNickNameView
import com.minhua.jijiehao2.utils.SPUtils
import com.minhua.jijiehao2.utils.T
import kotlinx.android.synthetic.main.activity_update_nick_name.*

class UpdateNickNameActivity : BaseActivity<IUpdateNickNameView, UpdateNickNamePresenter>(), IUpdateNickNameView {
    override fun getLayoutId(): Int = R.layout.activity_update_nick_name

    override fun getPresenter(): UpdateNickNamePresenter = UpdateNickNamePresenter()

    private val mOnClickListener = View.OnClickListener { v ->
        when (v.id) {
            R.id.tvRight -> mPresenter.updateName()
        }
    }


    override fun initView() {
        ctTitle.viewHolder.setOnClickListener(R.id.tvRight, mOnClickListener)
    }

    override fun getNickName(): String = tvNickName.text.trim()

    override fun onUpdateNameSuccess() {
        T.showShort("修改昵称成功")
        SPUtils.put(DefineKey.USER_NICK_NAME, getNickName())
        Handler().postDelayed({ startActivity(Intent(this, MainActivity::class.java)) }, 500)
    }
}
